(function(){
    function red () {
        console.log('red');
    }
    function green () {
        console.log('green');
    }
    function yellow () {
        console.log('yellow');
    }
    function start(){
        let promise1 = new Promise(function(resolve,reject){
            setTimeout(()=>{
                red();
                resolve();
            },3000);
        });
        let promise2 = promise1.then(()=>{
            return new Promise(function(resolve,reject){
                setTimeout(()=>{
                    green();
                    resolve();
                },1000);
            });
        });
        let promise3 = promise2.then(()=>{
            return new Promise(function(resolve,reject){
                setTimeout(()=>{
                    yellow();
                    resolve();
                },2000);
            });
        });
        promise3.then(()=>{
            start()
        });
    }
    start();
})()
